package com.flyoil.petromp.mvp_m.CourseDetailModel;

import com.flyoil.petromp.Constant.ConstantNetworkCode;
import com.flyoil.petromp.apiservice.OnObserverRetrofitResetCallBack;
import com.flyoil.petromp.base.BaseEntity;
import com.flyoil.petromp.entity.entity_course_detail.GoodsExamineDetailEntity;
import com.flyoil.petromp.entity.entity_order.MapListEntity;
import com.flyoil.petromp.base.BaseModel;
import com.flyoil.petromp.mvp_p.Listener.OnPresenterListener;
import com.flyoil.petromp.mvp_p.Listener.OrderGoodsMessageListener;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by songzhiyin on 2017/11/1.
 * 采购计划明细详情界面数据处理类
 */

public class GoodsExamineDetailModel implements BaseModel {

    @Override
    public void loadNetworkData(Map<String, Object> map, final OnPresenterListener onPresenterListener) {
        httpModel.getCourseGoodsExamineDetail(map, new OnObserverRetrofitResetCallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity model) {
                super.onSuccess(model);

                GoodsExamineDetailEntity goodsExamineDetailEntity = null;
                if (model instanceof GoodsExamineDetailEntity) {
                    goodsExamineDetailEntity = (GoodsExamineDetailEntity) model;
                }
                if (goodsExamineDetailEntity != null && goodsExamineDetailEntity.getData() != null && model.getCode() == ConstantNetworkCode.SuccedCode) {

                    GoodsExamineDetailEntity.DataBean dataBean = goodsExamineDetailEntity.getData();
                    OrderGoodsMessageListener listener = (OrderGoodsMessageListener) onPresenterListener;
                    List<MapListEntity> mapListEntities = new ArrayList<>();
                    mapListEntities.add(new MapListEntity("物资名称", dataBean.getMaterialName()));
                    mapListEntities.add(new MapListEntity("规格/型号", dataBean.getModel()));
                    mapListEntities.add(new MapListEntity("单位", dataBean.getUnit()));
                    mapListEntities.add(new MapListEntity("订货数量", dataBean.getOrderQuantity()));
                    mapListEntities.add(new MapListEntity("实收数量", dataBean.getReceivedQuantity()));
                    mapListEntities.add(new MapListEntity("外包装是否完好", dataBean.getPackageStatus()));
                    mapListEntities.add(new MapListEntity("有无外观缺陷", dataBean.getExteriorDefectsLabel()));
                    mapListEntities.add(new MapListEntity("发票号", dataBean.getInvoicesNo()));
                    mapListEntities.add(new MapListEntity("采购单价", dataBean.getPrice()));
                    mapListEntities.add(new MapListEntity("采购总价", dataBean.getTotalAmount()));
                    listener.upDataTextsView(mapListEntities);
                    if (dataBean.getFiles() != null) {
                        listener.upDataImgsView("物品照片", dataBean.getFiles());
                    }

                } else {
                    onPresenterListener.onsucced(null);
                }
            }

            @Override
            public void onFailure(String msg) {
                onPresenterListener.onsucced(null);
//                OrderGoodsMessageListener listener = (OrderGoodsMessageListener) onPresenterListener;
//                List<MapListEntity> mapListEntities = new ArrayList<>();
//                mapListEntities.add(new MapListEntity("物资名称", "摄像机"));
//                mapListEntities.add(new MapListEntity("规格/型号", "ES25412"));
//                mapListEntities.add(new MapListEntity("单位", "个"));
//                mapListEntities.add(new MapListEntity("订货数量", "20"));
//                mapListEntities.add(new MapListEntity("实收数量", "20"));
//                mapListEntities.add(new MapListEntity("外包装是否完好", "是"));
//                mapListEntities.add(new MapListEntity("有无外观缺陷", "无"));
//                mapListEntities.add(new MapListEntity("发票号", "24454515638165465"));
//                mapListEntities.add(new MapListEntity("采购单价", "100元"));
//                mapListEntities.add(new MapListEntity("采购总价", "2000元"));
//                listener.upDataTextsView(mapListEntities);
//
//                List<String> imgUrl = new ArrayList<>();
//                imgUrl.add("http://p0.so.qhimgs1.com/dmfd/326_204_/t012c852c8f981d6a00.jpg");
//                imgUrl.add("http://p2.so.qhmsg.com/dmfd/326_204_/t016f319fe697b397a7.jpg");
//                listener.upDataImgsView("物品照片", imgUrl);
            }
        });

    }
}
